{% extends 'register/base.html' %}
{% load i18n %}
{% if dataset.extents %}
{% block script %}
<style type="text/css">
<!--
 #preview {
                width: 450px;
                height: 180px;
                border: 1px solid black;
            }

-->
 </style>

<script src="{{ baseurl }}static/OpenLayers.js"></script>

<script type="text/javascript">
	function init() {
		divs = document.getElementsByTagName("div");
		for (i=0; i<divs.length; i++) {
			if (divs[i].className == "list_map") {
				kmlurl = divs[i].innerHTML;
				divs[i].innerHTML = "";
				map = new OpenLayers.Map(divs[i].id, { 'controls' : [] });
				basemap = new OpenLayers.Layer.WMS("vmap0","{{ tilecache }}", { layers : "basic" });
				map.addLayer(basemap);
				kml = new OpenLayers.Layer.GML("{{ object }}",
					kmlurl,
					{
						format: OpenLayers.Format.KML,
						formatOptions: {
							extractStyles: true,
							extractAttributes: false
						}
					}
				);
				map.addLayer(kml);
				map.zoomToMaxExtent();
			}
		}

{% if dataset.extents %}
	var map = new OpenLayers.Map("preview",{controls: []}); 
	basemap = new OpenLayers.Layer.WMS("vmap0","{{ tilecache }}", { layers : "basic" });
        map.addLayer(basemap);
	kml = new OpenLayers.Layer.GML("{{ dataset }}",
					{{ dataset.get_kml_url }},
					{
						format: OpenLayers.Format.KML,
						formatOptions: {
							extractStyles: true,
							extractAttributes: false
						}
					}
				);
	map.addLayer(kml);
         
        map.zoomToMaxExtent();  
{% endif %}

   }
</script>     
{% endblock  %}

{% endif %}

{% block title %}<title>:: duetopia :: {% trans 'dataset' %} - {{ dataset.title }}</title>{% endblock %}

{% block content %}
<h2>{{dataset}}</h2> 
<p class="links" align="right">As XML: <a href="rdf/">RDF</a>, <a href="iso19115/">ISO19115 (simple)</a></p>

<div id="metadata" class="metadata">

<table>
{% if dataset.name %}
<tr><th>{% trans 'name' %}</th><td>{{ dataset.name }}</td><td></td></tr>
{% endif %}
<tr><th>{% trans 'title' %}</th><td>{{dataset.title}}</td><td rowspan="3" valign="bottom"><a href="extend/text">{% trans 'edit' %}</a></td></tr>
<tr><th>{% trans 'abstract' %}</th><td>{{dataset.abstract}}</td></tr>

<tr><th>{% trans 'keywords' %}</th>
<td>
{% if dataset.keywords.filter %}
  {% for keyword in dataset.keywords.filter %}
    {{keyword}}
  {% endfor %}
{% endif %}
</td></tr>

        <tr><th>{% trans 'time period' %}</th>
        <td>
        {% if dataset.timespan %}
          {% if dataset.timespan.date %}
            {{ dataset.timespan.date }}
          {% else %}
           <b>{% trans 'start' %}</b>: {{ dataset.timespan.dtstart }} <br/>
           <b>{% trans 'end' %}</b>: {{ dataset.timespan.dtend }}
          {% endif %}
        {% endif %}
        </td><td> <a href="{{ baseurl }}timespan/for/dataset/{{ dataset.id }}">{% trans 'edit' %}</a></td></tr>
<tr><th>{% trans 'publication date' %}</th><td>{{ dataset.published }}</td><td rowspan="2"> <a href="extend/dates">{% trans 'edit' %}</a></td></tr>
<tr><th>{% trans 'last update date' %}</th><td>{{ dataset.updated }}</td></tr>

<tr><th>{% trans 'extents' %}</th><td>
{% if dataset.extents %}
<div id="preview"></div>
{% endif %}

</td><td><a href="extend/extents">{% trans 'edit' %}</a></td></tr>

<tr><th>{% trans 'contacts' %}</th><td>
{% for contact in dataset.contacts.filter %}
<div class="contact"><pre><a href="{{ baseurl }}agent/{{contact.id}}">{{contact}}</a></pre> <a href="detach/contact/{{contact.id}}">[detach]</a></div>
{% endfor %}
</td><td>
<a href="extend/contact">edit</a>
</td></tr>
</table>

<table>
<caption>{% trans 'data sources' %}</caption>

{% for source in dataset.datasource_set.filter %}
<tr><td>
{{source.format }}
</td>
<td align="right"> {{ source.link }} 
{% if source.timespan %}
 ({{ source.timespan }}) 
{% endif %}
<br/>
     <a href="{{ baseurl }}datasource/{{ source.id }}">{% trans 'view details' %}</a>    
</td></tr>
{% endfor %}
<tr><td colspan="2">
<a href="{{ baseurl }}datasource/add/to/{{dataset.id}}">add new</a></td>
</tr>
</table>

{% if dataset.layer_set.filter %}
<div class="layers">
<table>
<caption>{% trans 'layers' %}</caption>
<tr><th>{% trans 'name' %}</th><th>{% trans 'title' %}</th></tr>
{% for layer in dataset.layer_set.filter %}
<tr><td><a href="{{layer.get_absolute_url}}">{{layer.name}}</a></td>
    <td>{{layer.title_utf8}}</td>
    <td>{{layer.pextents}}</td>
</tr>
{% endfor %}
</table>
</div>
{% endif %}
{% endblock %}
